/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xrkol.sharelib.dao.TeachingDao;
import com.xrkol.sharelib.entity.Clazz;
import com.xrkol.sharelib.entity.Teacher;
import com.xrkol.sharelib.entity.Teaching;
import com.xrkol.sharelib.service.TeacherService;
import com.xrkol.sharelib.service.TeachingService;

/**
 * @author peng.xia
 * 
 */
@Service
@Transactional
public class TeachingServiceImpl implements TeachingService {

    @Autowired
    private TeachingDao teachingDao;

    @Autowired
    private TeacherService teacherService;

    @Override
    public void save(Teaching entity) {
        this.teachingDao.save(entity);
    }

    @Override
    public void update(Teaching entity) {
        this.teachingDao.update(entity);
    }

    @Override
    public void delete(String id) {
        this.teachingDao.delete(id);
    }

    @Override
    public Teaching findById(String id) {
        return this.teachingDao.findById(id);
    }

    @Override
    public void save(Clazz clazz, String[] teacherIds) {
        if (null == teacherIds) {
            return;
        }
        for (String tId : teacherIds) {
            Teaching teaching = new Teaching();
            Teacher teacher = this.teacherService.findById(tId);
            teaching.setclazz(clazz);
            teaching.setTeacher(teacher);
            this.teachingDao.save(teaching);
        }
    }

    @Override
    public void deleteByClass(Clazz clazz) {
        this.teachingDao.deleteByClass(clazz);
    }

}
